$('[name="name"]').blur(function () {
    let name = $('[name="name"]').val();
    var res = /^[^0-9][a-zA-Z0-9_]{1,12}$/;
    let bool = res.test(name);
    if (bool === false) {
        $('main .list:nth-of-type(1)').css('border-color', 'red');
    } else if (bool === true) {
        $('main .list:nth-of-type(1)').css('border-color', 'gray');
    }
})
$('[name="phone"]').blur(function () {
    let phone = $('[name="phone"]').val();
    var res = /^1\d{10}$/;
    let bool = res.test(phone);
    console.log(bool)
    if (bool === false) {
        $('main .list:nth-of-type(2)').css('border-color', 'red');
    } else if (bool === true) {
        $('main .list:nth-of-type(2)').css('border-color', 'gray');
    }
})
$('[name="education"]').blur(function () {
    let education = $('[name="education"]').val();
    if (education === '初中') {
        $('main .list:nth-of-type(3)').css('border-color', 'gray');
    } else if (education === '高中') {
        $('main .list:nth-of-type(3)').css('border-color', 'gray');
    } else if (education === '本科') {
        $('main .list:nth-of-type(3)').css('border-color', 'gray');
    } else if (education === '研究生') {
        $('main .list:nth-of-type(3)').css('border-color', 'gray');
    } else if (education === '硕士') {
        $('main .list:nth-of-type(3)').css('border-color', 'gray');
    } else {
        $('main .list:nth-of-type(3)').css('border-color', 'red');
    }
})
let sbj;
$('[name="save"]').click(function () {
    let name = $('[name="name"]').val();
    let phone = $('[name="phone"]').val();
    let education = $('[name="education"]').val();
    let age = $('[name="age"]').val();
    let money = $('[name="money"]').val();
    sbj = [
        {name:name,phone:phone,education:education,age:age,money:money},
    ]
    table();
})
const oTbody =document.querySelector('tbody')
oTbody.addEventListener( 'click' , function(e){
if( e.target.tagName === "BUTTON" ){
    if( window.confirm('您确定要删除吗?') ){

        sbj.splice( -1 , 1 );
        table()
    } 
}
})
function table(){
    let str =``;
    sbj.forEach(function(item,key){
        str +=`
            <tr>
            <td>${item.name}</td>
            <td>${item.phone}</td>
            <td>${item.education}</td>
            <td>${item.age}</td>
            <td>${item.money}</td>
            <td><button index="1">删除</button></td>
        `
    })
    sbj.push(str);
    $('tbody').append(sbj);
}